package com.gameShare.controller.user

import com.gameShare.controller.base.LoginVerifyController
import com.gameShare.entity.dto.user.UserFocusNumberDto
import com.gameShare.entity.vo.FocusUserVo
import com.gameShare.entity.vo.PageVo
import com.gameShare.entity.vo.ResponseVo
import com.gameShare.enums.user.UserFocusSelectType
import com.gameShare.service.user.UserFocusService
import jakarta.servlet.http.HttpServletRequest
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController


@RestController
@RequestMapping("userFocus")
class UserFocusController(private val userFocusService: UserFocusService) : LoginVerifyController() {


    @PostMapping("focus/{focusUserId}")
    fun focus(httpServletRequest: HttpServletRequest, @PathVariable focusUserId: String): ResponseVo<Boolean> {
        val userId = getUserInfoByToken(httpServletRequest).id
        return getSuccessResponseVO(userFocusService.focus(userId, focusUserId))
    }

    @PostMapping("cancelFocus/{focusUserId}")
    fun cancelFocus(httpServletRequest: HttpServletRequest, @PathVariable focusUserId : String): ResponseVo<Boolean> {
        val userId = getUserInfoByToken(httpServletRequest).id
        return getSuccessResponseVO(userFocusService.cancelFocus(userId,focusUserId))
    }

    @RequestMapping("loadUserFocusPage")
    fun loadUserFocusPage(httpServletRequest: HttpServletRequest, pageNo : Int?, pageSize : Int?, userId : String?, selectType: Int?): ResponseVo<PageVo<FocusUserVo?>> {
        return getSuccessResponseVO(userFocusService.loadUserFocusPage(
            pageNo,
            pageSize,
            userId ?: getUserIdByToken(httpServletRequest),
            selectType ?: UserFocusSelectType.FOCUS.code
        ))
    }

    @RequestMapping("loadUserFocusNumber")
    fun loadUserFocusNumber(@RequestParam userId : String): ResponseVo<UserFocusNumberDto> {
        return getSuccessResponseVO(userFocusService.loadUserFocusNumber(userId))
    }

}